<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>基金净值排行榜</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 40px;
            background-color: #f9f9f9;
            color: #333;
        }
        h1, h2 {
            color: #0056b3;
            text-align: center;
        }
        .container {
            display: flex;
            gap: 40px;
            justify-content: space-around;
            margin-top: 30px;
        }
        .column {
            width: 45%;
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        th, td {
            padding: 10px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
            color: #333;
        }
        tr:hover {
            background-color: #f5f5f5;
        }
        .gainer { color: #d32f2f; }
        .loser { color: #2e7d32; }
        .footer {
            text-align: center;
            margin-top: 40px;
            color: #666;
            font-size: 0.9em;
        }
    </style>
</head>
<body>

    <h1>📊 基金净值排行榜</h1>
    <p style="text-align:center;"><strong>数据更新时间：</strong>{{ update_time }}</p>

    <div class="container">
        <!-- 涨幅榜 -->
        <div class="column">
            <h2 class="gainer">📈 涨幅TOP 100</h2>
            <table>
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>基金代码</th>
                        <th>基金名称</th>
                        <th>最新净值({{ latest_date }})</th>
                        <th>涨跌幅(%)</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in gainers %}
                    <tr>
                        <td><strong>{{ loop.index }}</strong></td>           <!-- 排名 -->
                        <td>{{ item['基金代码'] }}</td>                      <!-- 基金代码 -->
                        <td>{{ item['基金简称'] }}</td>                      <!-- 基金简称 -->
                        <td>{{ "%.4f"|format(item[latest_net_value_col]|float) }}</td>  <!-- 最新净值 -->
                        <td style="color:#d32f2f; font-weight:bold;">
                            +{{ "%.2f"|format(item['日增长率']|float) }}%
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        <!-- 跌幅榜 -->
        <div class="column">
            <h2 class="loser">📉 跌幅TOP 100</h2>
            <table>
                <thead>
                    <tr>
                        <th>排名</th>
                        <th>基金代码</th>
                        <th>基金名称</th>
                        <th>最新净值({{ latest_date }})</th>
                        <th>涨跌幅(%)</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in losers %}
                    <tr>
                        <td><strong>{{ loop.index }}</strong></td>
                        <td>{{ item['基金代码'] }}</td>
                        <td>{{ item['基金简称'] }}</td>
                        <td>{{ "%.4f"|format(item[latest_net_value_col]|float) }}</td>
                        <td style="color:#2e7d32; font-weight:bold;">
                            {{ "%.2f"|format(item['日增长率']|float) }}%
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>

    <div class="footer">
        数据来源：东方财富 via AkShare | 刷新页面可重新加载最新数据
    </div>

</body>
</html>
